package com.ssy.lingxi.member.merchant.handler.validator;

import com.ssy.lingxi.common.constant.basic.PurchaseContractPayTypeEnum;
import com.ssy.lingxi.common.constant.member.BusinessCategoryInvoiceTypeEnum;
import com.ssy.lingxi.member.merchant.handler.annotation.BusinessCategoryInvoiceTypeAnnotation;
import com.ssy.lingxi.member.merchant.handler.annotation.PurchaseContractPayTypeAnnotation;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;
import java.util.Arrays;

/**
 * 会员入库分类 - 发票类型枚举校验注解验证类
 * @author 万宁
 * @version 2.0.0
 * @date 2021-12-16
 */
public class BusinessCategoryInvoiceTypeValidator implements ConstraintValidator<BusinessCategoryInvoiceTypeAnnotation, Integer> {
    @Override
    public boolean isValid(Integer value, ConstraintValidatorContext context) {
        if(value == null) {
            return false;
        }

        return Arrays.stream(BusinessCategoryInvoiceTypeEnum.values()).map(BusinessCategoryInvoiceTypeEnum::getCode).anyMatch(v -> v.equals(value));
    }
}
